﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using MVCSoict.Models;

namespace MVCSoict.Controllers
{
    public class InController : Controller
    {
        private staffsoictEntities1 db = new staffsoictEntities1();

        // GET: /In/
        public ActionResult Index()
        {
          
            return View();
        }

        // GET: /In/Details/5
        public ActionResult Details(string id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            In @in = db.Ins.Find(id);
            if (@in == null)
            {
                return HttpNotFound();
            }
            return View(@in);
        }

        // GET: /In/Create
        public ActionResult Create()
        {
            ViewBag.did = new SelectList(db.Departments, "did", "name");
            ViewBag.uid = new SelectList(db.Users, "username", "password");
            return View();
        }

        // POST: /In/Create
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include="uid,date,did")] In @in)
        {
            if (ModelState.IsValid)
            {
                db.Ins.Add(@in);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.did = new SelectList(db.Departments, "did", "name", @in.did);
            ViewBag.uid = new SelectList(db.Users, "username", "password", @in.uid);
            return View(@in);
        }

        // GET: /In/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            In @in = db.Ins.Find(id);
            if (@in == null)
            {
                return HttpNotFound();
            }
            ViewBag.did = new SelectList(db.Departments, "did", "name", @in.did);
            ViewBag.uid = new SelectList(db.Users, "username", "password", @in.uid);
            return View(@in);
        }

        // POST: /In/Edit/5
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for 
        // more details see http://go.microsoft.com/fwlink/?LinkId=317598.
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit([Bind(Include="uid,date,did")] In @in)
        {
            if (ModelState.IsValid)
            {
                db.Entry(@in).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.did = new SelectList(db.Departments, "did", "name", @in.did);
            ViewBag.uid = new SelectList(db.Users, "username", "password", @in.uid);
            return View(@in);
        }

        // GET: /In/Delete/5
        public ActionResult Delete(string id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            In @in = db.Ins.Find(id);
            if (@in == null)
            {
                return HttpNotFound();
            }
            return View(@in);
        }

        // POST: /In/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(string id)
        {
            In @in = db.Ins.Find(id);
            db.Ins.Remove(@in);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                db.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}
